package com.xtweb.config;

import java.util.Set;

import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.jfinal.core.JFinal;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.activerecord.CaseInsensitiveContainerFactory;
import com.jfinal.plugin.activerecord.dialect.OracleDialect;
import com.jfinal.plugin.druid.DruidPlugin;
import com.xtweb.model.*;

import org.beetl.core.GroupTemplate;
import org.beetl.ext.jfinal.BeetlRenderFactory;

@SuppressWarnings("unused")
public class GlobalCongfig extends JFinalConfig{

	@Override
	public void configConstant(Constants me) {
		loadPropertyFile("config.properties");	
		me.setMainRenderFactory(new BeetlRenderFactory());
        GroupTemplate groupTemplate = BeetlRenderFactory.groupTemplate;


		me.setDevMode(false);
		me.setEncoding(getProperty("config.encoding"));
	}

	@Override
	public void configRoute(Routes me) {
		me.add(new AdminRoute());
		me.add(new FrontRoute());
	}

	@Override
	public void configPlugin(Plugins me) {
		
		DruidPlugin dp = new DruidPlugin(getProperty("oracle.jdbcUrl"),getProperty("oracle.userName"),getProperty("oracle.passWord"),getProperty("oracle.driverClass"));
		dp.setValidationQuery("SELECT USERNAME FROM PT_USER");//验证连接语句
		me.add(dp);
		ActiveRecordPlugin arp = new ActiveRecordPlugin(dp);
		me.add(arp);
		//配置Oracle方言
		arp.setDialect(new OracleDialect());
		//配置字段名大小写不敏感
		arp.setContainerFactory(new CaseInsensitiveContainerFactory());
		//表映射
		arp.addMapping("PT_USER","IDS",Pt_User.class);
		arp.addMapping("PT_ROLE","IDS",Pt_Role.class);
		arp.addMapping("PT_MSGBOX","IDS", Pt_MsgBox.class);
		
	}

	@Override
	public void configInterceptor(Interceptors me) {}

	@Override
	public void configHandler(Handlers me) {}
	
	public void afterJFinalStart(){}
	public void beforeJFinalStop(){}

	public static void main(String[] args) {
		JFinal.start("WebRoot", 80, "/", 5);   
	}
}
